package com.doge.calcalbum.utils

import android.widget.Toast


fun toast(resId: Int?) {
    if (resId == null) return
    toast(appContext.getString(resId))
}

fun toast(message: String?) {
    if (message?.isNotEmpty() == true) {
        runOnUI { show(message) }
    }
}


private val toast by lazy { Toast.makeText(appContext, "", Toast.LENGTH_SHORT) }
private var timestamp: Long = 0
private var value: String? = null
private fun show(message: String) {
    if (message == value && System.currentTimeMillis() - timestamp < 2000) {
        return // filter repeat
    }
    timestamp = System.currentTimeMillis()
    value = message
    toast.setText(message)
    toast.show()
}